<?php

/**
 * @file
 * Default theme implementation to display the basic html structure of a single
 * Drupal page.
 *
 * Variables:
 * - $css: An array of CSS files for the current page.
 * - $language: (object) The language the site is being displayed in.
 *   $language->language contains its textual representation.
 *   $language->dir contains the language direction. It will either be 'ltr' or 'rtl'.
 * - $rdf_namespaces: All the RDF namespace prefixes used in the HTML document.
 * - $grddl_profile: A GRDDL profile allowing agents to extract the RDF data.
 * - $head_title: A modified version of the page title, for use in the TITLE
 *   tag.
 * - $head_title_array: (array) An associative array containing the string parts
 *   that were used to generate the $head_title variable, already prepared to be
 *   output as TITLE tag. The key/value pairs may contain one or more of the
 *   following, depending on conditions:
 *   - title: The title of the current page, if any.
 *   - name: The name of the site.
 *   - slogan: The slogan of the site, if any, and if there is no title.
 * - $head: Markup for the HEAD section (including meta tags, keyword tags, and
 *   so on).
 * - $styles: Style tags necessary to import all CSS files for the page.
 * - $scripts: Script tags necessary to load the JavaScript files and settings
 *   for the page.
 * - $page_top: Initial markup from any modules that have altered the
 *   page. This variable should always be output first, before all other dynamic
 *   content.
 * - $page: The rendered page content.
 * - $page_bottom: Final closing markup from any modules that have altered the
 *   page. This variable should always be output last, after all other dynamic
 *   content.
 * - $classes String of classes that can be used to style contextually through
 *   CSS.
 *
 * @see template_preprocess()
 * @see template_preprocess_html()
 * @see template_process()
 */
?><!DOCTYPE html>
<html lang="<?php print $language->language; ?>" dir="<?php print $language->dir; ?>"
<?php //print $rdf_namespaces; ?>>
<head>
  <?php print $head; ?>
  <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
  <meta name="MobileOptimized" content="width" />
  <meta name="HandheldFriendly" content="true" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta http-equiv="Cache-Control" content="no-siteapp">
  <meta name="renderer" content="webkit">
  <meta name="x5-orientation" content="portrait">
  <meta name="x5-page-mode" content="portrait">
  <title><?php print $head_title; ?></title>
  <?php print $styles; ?>
  <?php print $scripts; ?>
  <script>
  var pageWidthClass = function(cl) {
    return document.body.classList.contains(cl);
  }
  window.onload = function() {
    // date time
    if( pageWidthClass("page-node-add-disaster-report") ) {

      var time_input = document.querySelector("#edit-field-time input[type='text']");
      if(time_input) {
        var now       = <?php $now = time(); print '"'. date(DATE_ATOM, $now) .'"';?>.split("+")[0];
        var last_week = <?php $last_week = time() - (7 * 24 * 60 * 60); print '"'. date(DATE_ATOM, $last_week) .'"'?>.split("+")[0];
        time_input.setAttribute("type", "datetime-local");
        time_input.setAttribute("max", now);
        time_input.setAttribute("min", last_week);
      }

      // phone and number
      document.querySelector("#edit-field-phone input[type='text']").setAttribute("type", "tel");
      var dates = document.querySelectorAll("#edit-field-date input");
      for(var i=0;i<dates.length;i++) {
        dates[i].setAttribute("readonly", true);
      }
      var number_fields = [
        "edit-field-collapsed-amount",
        "edit-field-destroyed-amount",
        "edit-field-population",
        "edit-field-dead-amount",
        "edit-field-injured-amount"];
      for(n in number_fields) {
        var name = number_fields[n];
        var field = document.querySelector("#"+name+" input[type='text']");
        if(field) {
          field.setAttribute("type", "number");
          field.setAttribute("min", "0");
          field.removeAttribute("size");
          field.removeAttribute("maxlength");
        }
      }
    }
  }
  </script>
</head>
<body class="<?php print $classes; ?>" <?php print $attributes;?>>
  <?php print $page_top; ?>
  <?php print $page; ?>
  <?php print $page_bottom; ?>
</body>
</html>
